home *** CD-ROM | disk | FTP | other *** search
/ Power Tools for Macintosh / Power Tools for Macintosh (SoftBit)(1992).iso / Applications / Alpha 4.01 / ACMDS / Rot13.c < prev    next >
C/C++ Source or Header  |  1990-08-14  |  3KB  |  110 lines

  1. /****************************************************************
  2. *                                                               *
  3. * Rot 13  - shift characters 13 positions                       *
  4. *                                                               *
  5. * Copyright © 1990 Karl J. Smith. All Rights Reserved           *
  6. *                                                               *
  7. * email: ksmith@jarthur.claremont.edu                           *
  8. *                                                               *
  9. * 8/10/90                                                       *
  10. *                                                               *
  11. * When debugging, set the project type to application,          *
  12. * and add the ANSI project.                                     *
  13. *                                                               *
  14. * When all your bugs are out, 'undef' DEBUG, set the project    *
  15. * type to Code Resource, with type = ACMD, name = <the name     *
  16. * of the function>, file type to 'AEXT', and the purgeable      *
  17. * flag set to true.                                             *
  18. *                                                               *
  19. * Also, you need to remove the ANSI project from the ACMD       *
  20. * project and replace it with the ANSI-A4 project if you use    *
  21. * any functions in ANSI, such as strlen.                        *
  22. *                                                               *
  23. * If you are not using THINK C, I'm not quite sure what you     *
  24. * should do. :-)                                                *
  25. *                                                               *
  26. ****************************************************************/
  27.  
  28. #undef    DEBUG
  29.  
  30.  
  31. #include <stdio.h>
  32. #include <string.h>
  33.  
  34. /* Prototypes */
  35. char *
  36. #ifdef    DEBUG
  37. dummy(char *inStr);
  38. #else    DEBUG
  39. main(char *inStr);
  40. #endif    DEBUG
  41.  
  42. char *
  43. #ifdef    DEBUG
  44. dummy(inStr)
  45. #else    DEBUG
  46. main(inStr)
  47. #endif    DEBUG
  48. char    *inStr;
  49. {
  50.     char *currentChar;
  51.     
  52.     for (currentChar = inStr; *currentChar != 0; currentChar++)
  53.         {
  54.             if ((*currentChar >= 'A') && (*currentChar <= 'Z'))
  55.                 {
  56.                     *currentChar = ((*currentChar - 'A' + 13) % 26) + 'A';
  57.                 }
  58.             else if ((*currentChar >= 'a') && (*currentChar <= 'z'))
  59.                     {
  60.                         *currentChar = ((*currentChar - 'a' + 13) % 26) + 'a';
  61.                     }
  62.         }
  63.     return(inStr);
  64. }
  65.  
  66.  
  67. #ifdef    DEBUG
  68.  
  69. char * ConvertRtoN(char *theStr);
  70.  
  71. char * ConvertRtoN(theStr)
  72.     char *theStr;
  73. {
  74.     char *currentChar;
  75.     
  76.     for (currentChar = theStr;*currentChar != 0; currentChar++)
  77.         if (*currentChar == '\r')
  78.             *currentChar = '\n';
  79. }
  80.     
  81. main()
  82. {
  83.     char    *str = "Nice\rand\reasy\rABCDEFGHIJKLMNOPQRSTUVWXYZ\rabcdefghijklmnopqrstuvwxyz";
  84.     char    *ret;
  85.     char    once[255], twice[255];
  86.         
  87.     strcpy(once, str);
  88.     
  89.     ret = dummy(once);
  90.     strcpy(twice, once);
  91.     
  92.     ConvertRtoN(ret);                /* Convert '\r' to '\n' so we can see them in a printf */
  93.     ConvertRtoN(str);
  94.         
  95.     printf("The original is:\n\n%s", str);
  96.     printf("\n----\n\nThe result is:\n\n%s", ret);
  97.     
  98.     ret = dummy(twice);
  99.     ConvertRtoN(ret);                /* Convert '\r' to '\n' so we can see them in a printf */
  100.     printf("\n----\n\nThe result again is:\n\n%s", ret);
  101.     
  102. }
  103. #endif    DEBUG
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.